﻿using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using System.ComponentModel;
using System.Windows.Media;

namespace Chaos.model
{
    public class faction : INotifyPropertyChanged, stream.streamable
    {
        public event PropertyChangedEventHandler PropertyChanged;
        protected void Notify(string property)
        {
            if (this.PropertyChanged != null)
            {
                PropertyChanged(this, new PropertyChangedEventArgs(property));
            }
        }

        private String name;
        public String Name
        {
            get { return name; }
            set
            {
                if (name != value)
                {
                    name = value;
                    Notify("Name");
                }
            }
        }

        public String user;
        public String User
        {
            get { return user; }
            set
            {
                if (user != value)
                {
                    user = value;
                    Notify("User");
                    Notify("HasUser");
                }
            }
        }

        public bool locked;
        public bool Locked
        {
            get { return locked; }
            set
            {
                if (locked != value)
                {
                    locked = value;
                    Notify("Locked");

                }
            }
        }
        

        public bool HasUser
        {
            get { return User != ""; }
            set { }
        }

        
        private Color color;
        public Color Color
        {
            get { return color; }
            set
            {
                if (color != value)
                {
                    color = value;
                    Notify("Color");
                }
            }
        }

        private ObservableCollection<chaoscard> chaosdeck = new ObservableCollection<chaoscard>();
        public ObservableCollection<chaoscard> Chaosdeck
        {
            get { return chaosdeck; }
            set
            {
                if (chaosdeck != value)
                {
                    chaosdeck = value;
                    Notify("Chaosdeck");
                }
            }
        }

        private ObservableCollection<chaoscard> chaoshand = new ObservableCollection<chaoscard>();
        public ObservableCollection<chaoscard> Chaoshand
        {
            get { return chaoshand; }
            set
            {
                if (chaoshand != value)
                {
                    chaoshand = value;
                    Notify("Chaoshand");
                }
            }
        }


               
        public virtual void serialize(stream.stream io_Stream)
        {
            string c = Color.ToString();

            io_Stream.begin("faction")
                .serialize("Name", ref name)
                .serialize("User", ref user)
                .serialize("Locked", ref locked)
                //.serialize("Chaosdeck", ref chaosdeck)
                //.serialize("Chaoshand", ref chaoshand)
            .end();

            if (io_Stream.isinputstream())
            {
                Notify("User");
                Notify("HasUser");
                Notify("Name");
                Notify("Locked");
            }
        }
    }
}
